<template>
  <d-scroll-view  @refresherrefresh="getDetail" :refresher-triggered="triggered">
    <proj-detail-layout :process-instance-id="processInstanceId" :project-number="projectNumber">
      <d-forms label-width="180rpx">
        <d-forms-item label="评审资料">
          <text class="link-text" @click="gotoBasicInfo">《项目基础信息表》</text>
          <text class="link-text" @click="gotoCustomInfo">《客户信息表》</text>
          <text class="link-text" @click="gotoPromotionInfo">《项目推进表》</text>
        </d-forms-item>
        <d-forms-item label="评审理由" :input="form.reasonReview"></d-forms-item>
        <d-forms-item label="通知人员">
          <pm-user-select disabled :user-id="form.receivePersons"></pm-user-select>
        </d-forms-item>
      </d-forms>
    </proj-detail-layout>
  </d-scroll-view>
</template>

<script setup lang="ts">
import ProjDetailLayout from "@/components/ProjDetailLayout/index.vue";
import {usePreSalesEvaluateApi} from "@/api/pm/project/preSalesEvaluate";
import {RouteNameEnum} from "@/utils/pm/pmRoute";
import {queryToUrl} from "@/utils";

defineOptions({ name: 'PreSalesEvaluate' });

const projectNumber = ref<string>(null);
const processInstanceId = ref<string>(null);

const initForm = {
  projectNumber: null,
  isPass: null,
  projectName: null,
  processInstanceId: null,
  result: null,
  userId: null,
  storaged: null,
  projectId: null,
  id: null,
  resultCause: null,
  reasonReview: null,
  receivePerson: null,
  receivePersons: null,
}
const form = ref<PreSalesForm>(initForm)
const triggered = ref<boolean>(false);
function getDetail() {
  if(projectNumber.value) {
    triggered.value = true;
    usePreSalesEvaluateApi().getOppoFormByProjNum(projectNumber.value).then((res) => {
      if (res.code === 0 && res.data) {
        form.value = res.data;
      }
    }).finally(() => {
      triggered.value = false
    })
  }
}

function gotoBasicInfo() {
  uni.navigateTo({
    url: `/pmPages/project/detail/index?` +
    `component_name=${RouteNameEnum.projectBasicInfo}&` +
    `project_number=${projectNumber.value}`
  })
}

function gotoCustomInfo() {
  uni.navigateTo({
    url: queryToUrl('/pmPages/project/detail/index', {
      component_name: RouteNameEnum.customerInfo,
      project_number: projectNumber.value,
    })
  })
}

function gotoPromotionInfo() {
  uni.navigateTo({
    url: queryToUrl('/pmPages/project/detail/index', {
      component_name: RouteNameEnum.projectPromotionInfoTable,
      project_number: projectNumber.value,
    })
  })
}

onLoad((query) => {
  projectNumber.value = query['project_number']
  processInstanceId.value = query['process_instance_id']
  getDetail();
})
</script>

<style scoped lang="scss">

</style>
